package com.lm.jython.example;
import org.python.core.PyFunction;
import org.python.core.PyInteger;
import org.python.core.PyObject;
import org.python.util.PythonInterpreter;
public class JythonFunctionExample {
    public static void main(String[] args) {
        // 初始化 Python 解释器
        PythonInterpreter interpreter = new PythonInterpreter();

        // 加载 Python 脚本
        interpreter.execfile("E:\\lk\\springboot-example\\lm-jython\\src\\main\\resources\\py\\scriptAdd.py");

        // 获取函数对象
        PyFunction addFunction = (PyFunction) interpreter.get("add", PyFunction.class);

        // 调用函数
        PyObject result = addFunction.__call__(new PyObject[] {
                new PyInteger(10),
                new PyInteger(20)
        });

        System.out.println("Result: " + result);
    }
}
